package com.exigen.perflabstat.dao.jpa;

import java.util.List;

import javax.persistence.Query;

import com.exigen.perflabstat.base.GenericJPADAO;
import com.exigen.perflabstat.dao.TransactionTypeDao;
import com.exigen.perflabstat.models.TransactionType;

public class TransactionTypeJpaDao extends GenericJPADAO<TransactionType, Long> implements TransactionTypeDao {

	public TransactionTypeJpaDao() {
		super(TransactionType.class);
	}

	@SuppressWarnings("unchecked")
	public List<TransactionType> allTransactionTypes() {
		
		Query query = getEntityManager().createQuery("from TransactionType");
		
		List<TransactionType> result = query.getResultList();
		
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public TransactionType findByTransactionType(String transactionTypeName) {

		TransactionType transactionType = null;
		
		Query query = getEntityManager().createQuery("select transactionType from TransactionType transactionType where transactionType.TRANSACTION_TYPE = :transactionTypeName");
		query.setParameter("transactionTypeName", transactionTypeName);
		query.setMaxResults(1);
		
		List<TransactionType> result = query.getResultList();
		
		if(result.isEmpty())return null;
		
		transactionType = result.get(0);
		
		return transactionType;
	}
	
}
